package com.basic.bio.chat.groupchatdemo;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * @Description:服务器端
 * @Author:Zc9741
 * @QQ:516906531
 */
public class ServerSendRunnable implements Runnable{

    private Socket socket;

    public ServerSendRunnable(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        System.out.println("服务端开始发消息咯。。。");
        Scanner sc = null;
        try {
            sc = new Scanner(System.in);
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
            while (sc.hasNext()){
                writer.write(sc.nextLine());
                writer.newLine();
                writer.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            sc.close();
        }
    }
}

